/*
 * Copyright (c) 2000-2017 wanglei. All rights reserved.
 * TeamDev PROPRIETARY and CONFIDENTIAL.
 * Use is subject to license terms.
 */

package com.xhb.ui;


import com.teamdev.jxbrowser.browser.Browser;
import com.teamdev.jxbrowser.view.swing.BrowserView;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

/**
 * @author wanglei.
 */
public final class TabFactory {



    public static Tab createTab(Browser browser) {
        return createTab("about:blank",browser);
    }

    public static Tab createTab(String url,Browser browser) {
        BrowserView browserView = BrowserView.newInstance(browser);
        TabContent tabContent = new TabContent(browserView);
        final TabCaption tabCaption = new TabCaption();
        tabCaption.setTitle("about:blank");
        tabContent.addPropertyChangeListener("PageTitleChanged", new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                tabCaption.setTitle((String) evt.getNewValue());
            }
        });
        browser.navigation().loadUrl(url);
        tabContent.getToolBar().setUrl(url);
        return new Tab(tabCaption, tabContent);
    }
}
